package jindong;

import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main3 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n,t;
        n=scanner.nextInt();
        t=scanner.nextInt();
        Node[] node=new Node[n];
        for(int i=0;i<n;++i){
            int aT=scanner.nextInt();
            int aS=scanner.nextInt();
            int bT=scanner.nextInt();
            int bS=scanner.nextInt();
            double aAv=(double) aS/aT;
            double bAv=(double) bS/bT;
            double Av;
            boolean flag=true;
            if(aAv>=bAv){//优先正解
                Av=aAv;
            }else{
                Av=bAv;
                flag=false;
            }
            node[i]=new Node(i,aT,aS,bT,bS,aAv,bAv,Av,flag);
        }
        Arrays.sort(node, (o1, o2) -> {
            if(o1.Av-o2.Av>0){
                return -1;
            }else{
                return 1;
            }
        });
        for (int i=0;i<n;++i){
            System.out.println(node[i].toString());
        }
        int ans=0;int time=t;
        for(int i=0;i<n;++i){
            if(node[i].flag){//正解的效益高
                if(time-node[i].aT>=0){
                    ans+=node[i].aS;
                    time-=node[i].aT;
                    node[i].result='A';
                }
            }else{//暴力的效率高
                if(time-node[i].bT>=0){
                    ans+=node[i].bS;
                    time-=node[i].bT;
                    node[i].result='B';
                }
            }
        }
        Arrays.sort(node, new Comparator<Node>() {
            @Override
            public int compare(Node o1, Node o2) {
                return o1.index-o2.index;
            }
        });
        System.out.println();
        for(int i=0;i<n;++i){
            System.out.print(node[i].result);
        }
        System.out.println();
        for (int i=0;i<n;++i){
            System.out.println(node[i].toString());
        }
    }
}

class Node implements Comparable<Node>{
    int index;

    int aT;
    int aS;
    int bT;
    int bS;
    double aAv;//正解的性价比
    double bAv;//暴力的性价比
    double Av;//最高性价比
    boolean flag=true;//true代表选择正解
    char result='F';

    public Node(int index,int aT, int aS, int bT, int bS, double aAv, double bAv, double av,boolean flag) {
        this.index=index;
        this.aT = aT;
        this.aS = aS;
        this.bT = bT;
        this.bS = bS;
        this.aAv = aAv;
        this.bAv = bAv;
        Av = av;
        this.flag=flag;
    }

    @Override
    public String toString() {
        return "Node{" +
                "index=" + index +
                ", aT=" + aT +
                ", aS=" + aS +
                ", bT=" + bT +
                ", bS=" + bS +
                ", aAv=" + aAv +
                ", bAv=" + bAv +
                ", Av=" + Av +
                ", flag=" + flag +
                ", result=" + result +
                '}';
    }

    @Override
    public int compareTo(Node o) {
        return 0;
    }
}